package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Address;
import com.itheima.reggie.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//地址
@RestController
public class AddressController {
    @Autowired
    private AddressService addressService;

    //查看所有地址
    @GetMapping("/address/list")
    public ResultInfo list() {
        List<Address> list = addressService.list();

        return ResultInfo.success(list);
    }

    //新增地址
    @PostMapping("/address")
    public ResultInfo save(@RequestBody Address address) {
        addressService.save(address);
        return ResultInfo.success();

    }

    //设置默认地址
    @PutMapping("/address/default")
    public ResultInfo defaultSet(@RequestBody Address address) {
        addressService.defaultSet(address);
        return ResultInfo.success();
    }

    //查看默认地址
    @GetMapping("/address/default")
    public ResultInfo findDefault() {
        Address address = addressService.findDefault();


        return ResultInfo.success(address);
    }
    //地址回显
    @GetMapping("/address/{id}")
    public ResultInfo selectById( @PathVariable Long id){

           Address address =addressService.selectById(id);
        return ResultInfo.success(address);
    }
    //修改地址信息
    @PutMapping("/address")
    public ResultInfo update(@RequestBody Address address){
          addressService.update(address);
        return  ResultInfo.success();
    }

}
